<template>
	<view>
		<view class="container">
<!-- 			<view v-for="(item,index) in title" :key="index" >
				<view class="row">
					<view class="title">{{item}}:</view>
					<input class="box" type="text" @input="onInput"/>
				</view>
				<view class="view_line"></view>
			</view>	 -->
			<view>基本信息</view>
			<van-cell-group>
			<view v-for="(item,index) in title" :key="index" >
				  <van-field
				    :data-index='index'
					:value="value.nem"
					clearable
					:label="item"
					@change="onChange($event,nem)"
				  />
			 </view>
			 <van-field
				  :value="datestart"
				  required
				  clearable
				  label="开始时间"
				  placeholder="   格式:2021-05-20"
				/> 
				<van-field
				  :value="datedeadline"
				  required
				  clearable
				  label="结束时间"
				  placeholder="   格式:2021-05-20"
				/>
				
			 </van-cell-group>
			 <view class="logo">
				 <view class="text">点击上传公司logo</view>
				 <image :src="changeImg" class="Img" @click="upload"></image>
			</view>
		</view>
		<view class="container">
			<view>职位信息</view>
			<van-cell-group>
			<van-field
				:value="workName"
				  clearable
				  label="职位名称"
			/>			   
			<van-field
				:value="eduReq"
				  clearable
				  label="学历要求"
			/>
			<van-field
				:value="eduReq"
				  clearable
				  label="薪资待遇"
			/>
			<view class="uni-form-item uni-column label">
				<picker @change="bindPickerChange" :range="array">	
					<label>就职城市</label> 
					<label class="pick">{{array[index]}}</label>		
				</picker>
			</view>
			<van-field
				:value="eduReq"
				  clearable
				  type="textarea"
				  label="职位描述"
				  autosize
			/>
			<van-field
				:value="eduReq"
				  clearable
				  type="textarea"
				  label="其他"
				  autosize
			/>
			</van-cell-group>
		</view>
			<button @click="submit" class="submit" type="primary">发布</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:['公司名称','公司简介','内推码','联系人','联系电话','网申链接','投递邮箱'],
				datestart:'',
				datedeadline:'',
				changeImg:'',
				value:[],
				workName:'',
				eduReq:'',
				array:['城市选择▽','北京','西安','南京','上海','武汉','深圳','广州','成都',
				'重庆','杭州','天津'],
				index:0,
			}
		},
		
		methods: {
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e)//改变的事件名
				//console.log('picker发送选择改变，携带值为', e.target.value)   用于输出改变索引值
				this.index = e.target.value			//将数组改变索引赋给定义的index变量
				this.jg=this.array[this.index]		//将array【改变索引】的值赋给定义的jg变量
			//	console.log("籍贯为：",this.jg)		//输出获取的籍贯值，例如：中国
			},
			upload : function(){
			let that=this
			   uni.chooseImage({
			    count: 1,
			    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			    sourceType: ['album'], //从相册选择
			    success: function (res) {
			     const tempFilePaths = res.tempFilePaths;//本地路径
				 console.log('本地路径',tempFilePaths);
				 that.changeImg = tempFilePaths[0];
				 console.log('changImg', that.changeImg);
			     const uploadTask = uni.uploadFile({
				  url:'https://hotenergy.club/workapp/user/get_url',
			      filePath: tempFilePaths[0],
			      name: 'file',
			 	  header:{"Content-Type": "multipart/form-data"},
			      success: function (uploadFileRes) {
					console.log(uploadFileRes)
			       console.log('后台',uploadFileRes.data);
			      }
			     });
			    },
			    error : function(e){
			     console.log('错误',e);
			    }
			   });
			  },
			 onChange(event,value) {
			    // event.detail 为当前输入的值
			    console.log('当前输入',event.detail);	
				console.log('index',event.currentTarget.dataset.index);	
				this.value[event.currentTarget.dataset.index]=event.detail;
				console.log('value',this.value);	
			  },
			  submit(){
				  uni.request({
					  header: {
					       	      'Content-Type': 'application/json'  
					       	   }, 
					      url:'https://hotenergy.club/workapp/user/publish_work', 
					       method: 'POST',
					           data: {//字段写全
/* 					                   companyName: "拼多多9",
					                   intro: "房地产|已上市|20000+人",
					                   culture: "王思聪国民老公",
					                   cityId: 1,
					                   userId: 11,
					                   info:"一个很大的公司",
					                   iconUrl: "https://workapp.oss-cn-beijing.aliyuncs.com/images/2021/05/21/16215635882443195.jpg", 
					                   workName: "清洁工",
					                   eduReq: "大专毕业",
					                   sepcialCode: "IHFNOIFNCM",
					                   sepcialPerson: "王思聪",
					                   applicationDate: "2021-08-08",
					                   deadline: "2021-11-08",
					                   url: "www.wd.com",
					                   description: "会扫地",
					                   requirement: "无",
					                   other: "666",
					                   salary: "10K/月",
					                   workCategory: 0,
					                   industryId: 7,
					                   email: "313159585@qqq.com",
					                   tagId: 1 */
									   companyName: "拼多多9",
					                   intro: "房地产|已上市|20000+人",
					                   culture: "王思聪国民老公",
					                   cityId: 1,
					                   userId: 11,
					                   info:"一个很大的公司",
					                   iconUrl: "https://workapp.oss-cn-beijing.aliyuncs.com/images/2021/05/21/16215635882443195.jpg",
					                   
					                   workName: "清洁工",
					                   eduReq: "大专毕业",
					                   sepcialCode: "IHFNOIFNCM",
					                   sepcialPerson: "王思聪",
					                   applicationDate: "2021-08-08",
					                   deadline: "2021-11-08",
					                   url: "www.wd.com",
					                   description: "会扫地",
					                   requirement: "无",
					                   other: "666",
					                   salary: "10K/月",
					                   workCategory: 0,
					                   industryId: 7,
					                   email: "313159585@qqq.com",
					                   tagId: 1 									   
					           },
					       success: (res) => {
					       	 	console.log(res);
								uni.showToast({
									title:'发布成功'
								})
					           } 
				  })
				},
				}
		
	}
</script>

<style>
.container{
		display: flex;
		flex-direction: column;
		border-radius: 15rpx;
		margin: 50rpx 5% 0 5%;//上左下右		
	}
.row{
	display: flex;
	flex-direction: row;
	margin-bottom: 5rpx;
}
.title{
	margin-right: 20rpx;
}
.submit{
	width: 400rpx;
	margin-left: 175rpx;
	margin-top: 70rpx;
	margin-bottom: 200rpx;
	background-color: #666FFC !important;
}
.logo{
	display: flex;
	flex-direction: row;
	margin-left: 30rpx;
}
.text{
	font-size:90%;
	margin-top: 10rpx;		
}
.Img{
	margin-top: 5rpx;
	margin-left: 50rpx;
	width: 50rpx;
	height: 50rpx;
	background-color: #f3f3f3;
	border: 1px solid #f3f3f3; 
	background-image: url(../../static/shangchuantupian.png);/* 上传图片 */
	background-size: 100% 100%;
}
.label{
	margin: 15rpx 0 15rpx 30rpx;
	font-size: 90%;
}
.pick{
	margin-left: 76rpx;
	color: #999999;
}
/* 	.view_line {
		height: 5rpx;
		background: #f3f3f3;
		text-align: center;
		margin-bottom: 30rpx;
	} */
</style>
